<!DOCTYPE html>
<html>
<head>
    <title>工装基础档案选择</title>
    #parse("sys/header.html")
    <style>
        .col-sm-2 {
            width: 30%;
        }
        .sugon_upload_btn {
            display: -webkit-inline-box;
            display: inline-block;
        }
         .details td, .details th{
             vertical-align: text-bottom;
         }
    </style>
</head>
<body>
<div id="rrapp" v-cloak>
    <div>
        <Row :gutter="16" style="margin: 8px 0px 0px 1px">
            <div class="search-group">
                <i-col span="3">
                    <i-input v-model="q.name" @on-enter="query" placeholder="名称"></i-input>
                </i-col>
                <i-col span="3">
                    <i-input v-model="q.mapNo" @on-enter="query" placeholder="图号"></i-input>
                </i-col>
                <i-col span="3">
                    <i-input v-model="q.type" @on-enter="query" placeholder="规格"></i-input>
                </i-col>
                <i-button @click="query">查询</i-button>
                <i-button @click="reloadSearch">重置</i-button>
            </div>
        </Row>
        <table id="jqGrid"></table>
    </div>
</div>
<script>
    $(function () {
        var queryUrl = '../toolsbase/list';
        var itemId =  getQueryString('itemId');
        var controlWay = getQueryString('controlWay');
        queryUrl += '?itemId=' + itemId + '&controlWay=' + controlWay;
        $("#jqGrid").Grid({
            url: queryUrl,
            rownumWidth: 40,
            colModel: [
                {label: '名称', name: 'name', index: 'NAME'},
                {label: 'ERP编码', name: 'erpCode', index: 'ERP_CODE', width: 120},
                {label: '图号', name: 'mapNo', index: 'MAP_NO'},
                {label: '自制图号', name: 'createNo', index: 'CREATE_NO'},
                {label: '型号规格', name: 'type', index: 'TYPE'},
                {label: '适用机型', name: 'applicableModel', index: 'APPLICABLE_MODEL', width: 80},
                {
                    label: '是否易损', name: 'isVulnerable', index: 'IS_VULNERABLE', width: 60, formatter: function (value) {
                        return value === 0 ?
                            '<span class="label label-danger">否</span>' :
                            '<span class="label label-success">是</span>';
                    }
                },
                {label: '工装类别', name: 'typeName', index: 'TOOLS_TYPE', width: 60},
                {label: '管控方式', name: 'controlWayName', index: 'CONTROL_WAY'},
                {
                    label: '校验标准', width: 80, align: 'center', sortable: false,
                    formatter: function (value, col, row) {
                        return "<button title='查看周期性校验标准' class='btn btn-outline btn-info' onclick='vm.viewCheckStandard(\"" + row.id + "\", \"" + row.controlWay + "\")'><i class='fa fa-file-text-o'></i></button>";
                    }
                },
                {name: 'controlWay', hidden: true},
                {name: 'toolsType', hidden: true},
                {label: 'id', name: 'id', index: 'ID', key: true, hidden: true},
            ]
        });
    });
    var vm = new Vue({
        el: '#rrapp',
        data: {
            q: {
                name: '',
                mapNo: '',
                type: '',
                productLineIds: '',
            }
        },
        methods: {
            viewCheckStandard: function (id,controlWay) {
                // 查看周期性检验标准
                if(!controlWay || controlWay.indexOf('02') < 0){
                    iview.Message.error("只可以查看周期性精度检测的记录！");
                    return;
                }
                openWindow({
                    type: 2,
                    title: '<i class="fa fa-bars"></i> 周期性精密校验判定标准',
                    content: '../tools/toolscheckjudgestandard.html?toolsFileId=' + id
                })
            },
            query: function () {
                vm.reload();
            },
            reload: function (event) {
                // 清空postData缓存数据
                var postData = $("#jqGrid").jqGrid("getGridParam", "postData");
                $.each(postData, function (k, v) {
                    delete postData[k];
                });
                vm.showList = true;
                var page = $("#jqGrid").jqGrid('getGridParam', 'page');
                $("#jqGrid").jqGrid('setGridParam', {
                    postData: vm.q,
                    page: page
                }).trigger("reloadGrid");
            },
            reloadSearch: function () {
                vm.q = {
                    name: '',
                    mapNo: '',
                    type: '',
                    productLineIds: ''
                };
                deptZtree.cancelSelectedNode();
                vm.reload();
            }
        }
    });
    var getToolsbase = function () {
        let result = getSelectedRowData("#jqGrid");
        if(result.length == 0){
            iview.Message.error("请至少选择一件工装");
            return;
        }
        return result;
    }
</script>
</body>
</html>
